#!/bin/bash
set -e
set -x

BUILD_DEBUG="${BUILD_DEBUG:-}"
if [[ -n "${BUILD_DEBUG}" ]]; then
    set -x
    env
fi

cd $(dirname $0)/..

echo "Bootstrapping..."
yarn --pure-lockfile install

source scripts/version
echo "BRANCH: ${COMMIT_BRANCH:-<none>}"
echo "TAG: ${GIT_TAG:-<none>}"
DIR=${GIT_TAG:-$COMMIT_BRANCH}

echo "Building..."
OUTPUT_DIR=dist/${DIR}-embedded ROUTER_BASE='/dashboard' yarn run build --spa

TARBALL=${DIR}.tar.gz
echo "Compressing to ${TARBALL}..."
tar -czf dist/${TARBALL} dist/${DIR}-embedded/

echo "Cleaning up..."
rm -r dist/${DIR}-embedded

ls -alR dist/
